import vue from '@vitejs/plugin-vue';
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';

// 网站标题
const htmlTransform = (opts: any) => {
    return {
        name: 'html-transform',
        transformIndexHtml(html) {
            return html.replace(
                /<title>(.*?)<\/title>/,
                `<title>${opts.title}</title>`
            )
        }
    }
}

// icon 
const vitePluginSvgIcons = (opts: any) => createSvgIconsPlugin({
    iconDirs: [opts.iconDirs],
    symbolId: 'icon-[dir]-[name]',
})

const plugin = (opts: any) => {
    return [
        vue(),
        htmlTransform(opts.htmlTransform),
        vitePluginSvgIcons(opts.vitePlugionSvgIcons)
    ]
}

export default plugin